package jmine.tec.batch.export;

import java.util.LinkedList;
import java.util.List;

import jmine.tec.batch.domain.MPhase;
import jmine.tec.batch.domain.MProcess;
import jmine.tec.batch.services.MProcessService;
import jmine.tec.services.api.export.AbstractServiceFillerEntityExporter;
import jmine.tec.services.api.export.DefaultExportAction;

/**
 * Exporter da entidade {@link MProcess}.
 * 
 * @author Rafael Volpato
 * @date Nov 3, 2009
 */
public class MProcessExporter extends AbstractServiceFillerEntityExporter<MProcess> {

    /**
     * Construtor.
     */
    public MProcessExporter() {
        super(new MProcessService(), DefaultExportAction.INCLUIR);
    }

    /**
     * Marcar para exportação todas as {@link MPhase} associadas a esse {@link MProcess}.
     * 
     * @param entity {@link MProcess}
     * @return lista contendo todas as {@link MPhase} associadas a esse {@link MProcess}
     */
    @Override
    public List<Object> exportBefore(MProcess entity) {
        List<Object> result = new LinkedList<Object>(super.exportBefore(entity));

        result.addAll(entity.getPhases());

        return result;
    }

    /**
     * Marca para exportação a associação entre {@link MProcess} e {@link MPhase}.
     * 
     * @param entity {@link MProcess}
     * @return lista contendo a associação entre {@link MProcess} e {@link MPhase}
     */
    @Override
    public List<Object> exportAfter(MProcess entity) {
        List<Object> result = new LinkedList<Object>(super.exportAfter(entity));

        for (MPhase phase : entity.getPhases()) {
            result.add(new MPhaseToMProcessAssociation(phase, entity));
        }

        return result;
    }
}
